package com.freedom.pms.goods.infrastructure.persistence.repository;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.freedom.pms.goods.domain.pojo.bo.GoodsSpuBO;
import com.freedom.pms.goods.domain.repository.GoodsSpuRepository;
import com.freedom.pms.goods.infrastructure.persistence.assembler.GoodsSpuAssembler;
import com.freedom.pms.goods.infrastructure.persistence.mapper.GoodsSpuMapper;
import com.freedom.pms.goods.infrastructure.persistence.pojo.po.GoodsSpuPO;
import com.freedom.pms.goods.infrastructure.persistence.pojo.query.AdminSpuPageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class GoodsSpuRepositoryImpl implements GoodsSpuRepository {

    private final GoodsSpuMapper goodsSpuMapper;

    private final GoodsSpuAssembler goodsSpuAssembler;

    @Override
    public Page<GoodsSpuBO> queryGoodsSpuPage(AdminSpuPageQuery queryParam) {
        Page<GoodsSpuPO> page = new Page<>(queryParam.getCurrent(), queryParam.getPageSize());
        Page<GoodsSpuPO> goodsSpuPOPage = goodsSpuMapper.selectGoodsSpuPage(page, queryParam);
        return goodsSpuAssembler.toBOPage(goodsSpuPOPage);
    }

    @Override
    public GoodsSpuBO findAdminDetail(Integer id) {
        GoodsSpuPO goodsSpuPO = goodsSpuMapper.selectAdminDetail(id);
        return goodsSpuAssembler.toBO(goodsSpuPO);
    }


}